package com.leadership.api.entity;

import java.util.Date;
import java.util.Map;
import org.springframework.format.annotation.DateTimeFormat;
import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;

public class SapUserSearch implements QueryBuilder {
    
    @DateTimeFormat(pattern = "yyyyMMdd")
    private Date starttime;
    
    @DateTimeFormat(pattern = "yyyyMMdd")
    private Date endtime;
    
    private String usernumber;
    
    private QueryFilter filter;
    
    private QueryOrder order;
    
    /**
     * 
     */
    public SapUserSearch() {
        order = new QueryOrder();
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {
        
        if (filter == null || refresh) {
            
            filter = new QueryFilter().addDateBetween("modifyTime", starttime, endtime)
                                        .addEquals("trainee.code", usernumber);
        }
        
        return filter;
        
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public QueryOrder getOrder() {
        return order;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        String sentence = "FROM ProjectTrainee Where complete = true AND project.saved = true AND createTime IS NOT NULL" + getPreparedFilter(false).clauseSentence() + order.sentence();
        return sentence;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }
    
    public Date getStarttime() {
        return starttime;
    }
    
    public void setStarttime(Date starttime) {
        this.starttime = starttime;
    }
    
    public Date getEndtime() {
        return endtime;
    }
    
    public void setEndtime(Date endtime) {
        this.endtime = endtime;
    }
    
    public String getUsernumber() {
        return usernumber;
    }
    
    public void setUsernumber(String usernumber) {
        this.usernumber = usernumber;
    }
    
}
